package net.achun.exception;

import groovy.util.logging.Slf4j;
import net.achun.util.JsonData;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
@lombok.extern.slf4j.Slf4j


@Slf4j
@ControllerAdvice
public class ExceptionHandle {

    @ResponseBody
    @ExceptionHandler(value = Exception.class)
    public JsonData handle(Exception e){

        if (e instanceof BizException){

            BizException bizException = (BizException) e;
            log.info("[业务异常]{}",e);
            return JsonData.buildCodeAndMsg(bizException.getCode(), bizException.getMsg());
        } else {
            log.info("[系统异常]{}",e);
            return JsonData.buildError("全局异常,未知错误");
        }

    }

}
